﻿using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
    #region SupplierDAL
    public class SupplierDAL : DBContext
    {
        public List<Supplier> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_SuppliersSelectAll");
            return GetEntityList<Supplier>(cmd);
        }

        public Supplier GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_SupplierSelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<Supplier>(cmd);
        }

        public Supplier Add(
        string paramName,

        string paramAddress1,

        string paramAddress2,

        string paramAddress3,

        string paramCreatedBy
            )
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_SupplierInsert");
            cmd.AddParameter("@Name", paramName);
            cmd.AddParameter("@Address1", paramAddress1);
            cmd.AddParameter("@Address2", paramAddress2);
            cmd.AddParameter("@Address3", paramAddress3);
            cmd.AddParameter("@CreatedBy", paramCreatedBy);
            return GetSingleEntity<Supplier>(cmd);
        }

        public List<Supplier> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_SupplierSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<Supplier>(cmd);
        }

        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_SupplierDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public Supplier UpdateById(
        Guid paramId,

        string paramName,

        string paramAddress1,

        string paramAddress2,

        string paramAddress3,

        string paramUpdatedBy
            )
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_SupplierUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@Name", paramName);
			cmd.AddParameter("@Address1", paramAddress1);
			cmd.AddParameter("@Address2", paramAddress2);
			cmd.AddParameter("@Address3", paramAddress3);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return GetSingleEntity<Supplier>(cmd);
        }

    }
    #endregion
}
